<template>
  <main id="main" ref="main" style="width: 100%;height:100%;"></main>
</template>

<script lang="js">
const echarts = require("echarts")
export default {
  name: "cBar",
  props: {
    barData: {
      type: Object
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.initCarts();
  },
  methods: {
    initCarts() {
      this.chart = echarts.init(this.$refs['main'])
      const option = {
        tooltip: {},
        legend: {
          data: ['结余', '拨付比'],
          top: "-2%",
          left: '6%'
        },
        grid: {
          top: '15%',
          left: '0%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: "category",
            data: this.barData.xAxis,
            axisLabel: {
              textStyle: {
                color: '#484D78',
                fontSize: 12
              }
            },
            axisLine: {
              show: false
            },
            axisTick: {
              show: false
            },
            splitLine: {
              show: false,
            }
          },
        ],
        yAxis: [
          {
            name: "万元",
            nameLocation: "end",
            nameGap: 10,
            nameTextStyle: {
              align: "right"
            },
            splitArea: {show: false},
            type: 'value',
            axisLabel: {
              formatter: '{value}',
              textStyle: {
                align: 'right',
                color: '#484D78',
                fontSize: 12
              }
            }
          },
          {
            type: 'value',
            min: -100,
            max: 150,
            position: 'right',
            axisLabel: {
              formatter: '{value} %'
            },
            axisLine: {
              show: false
            },
            axisTick: {
              show: false
            },
            splitLine: {
              show: false,
            }
          }
        ],
        series: [
          {
            name: '结余',
            type: 'bar',
            emphasis: {
              itemStyle: {
                barBorderWidth: 1,
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowOffsetY: 0,
                shadowColor: 'rgba(0,0,0,0.5)'
              }
            },
            data: this.barData.surplus
          },
          {
            name: '拨付比',
            type: 'line',
            data: this.barData.proportion,
            lineStyle: {
              width: 2,
              color: "#FF8D49"
            },
            itemStyle: {
              color: "#FF8D49"
            }
          }
        ]
      };
      this.chart.setOption(option);
    }
  }
}
</script>

<style scoped lang="stylus">

</style>
